﻿namespace Sai.Core.Reporting
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    public class EmbeddedReportTransformationRepository : IReportTransformationRepository
    {
        private Dictionary<TypeFormatPair, string> typeFileMap = new Dictionary<TypeFormatPair, string>();

        public EmbeddedReportTransformationRepository()
        {
            this.typeFileMap.Add(new TypeFormatPair(typeof(IProductReleaseDifference), ReportFormat.Html), "Sai.Core.Reporting.SummaryHtml.xslt");
            this.typeFileMap.Add(new TypeFormatPair(typeof(IAssemblyDifference), ReportFormat.Html), "Sai.Core.Reporting.AssemblyHtml.xslt");
            this.typeFileMap.Add(new TypeFormatPair(typeof(ITypeDifference), ReportFormat.Html), "Sai.Core.Reporting.TypeHtml.xslt");
            this.typeFileMap.Add(new TypeFormatPair(typeof(ITypeListing), ReportFormat.Html), "Sai.Core.Reporting.ListingHtml.xslt");
            
            this.typeFileMap.Add(new TypeFormatPair(typeof(IProductReleaseDifference), ReportFormat.Html4), "Sai.Core.Reporting.SummaryHtml4.xslt");
            this.typeFileMap.Add(new TypeFormatPair(typeof(IAssemblyDifference), ReportFormat.Html4), "Sai.Core.Reporting.AssemblyHtml4.xslt");
            this.typeFileMap.Add(new TypeFormatPair(typeof(ITypeDifference), ReportFormat.Html4), "Sai.Core.Reporting.TypeHtml4.xslt");
            this.typeFileMap.Add(new TypeFormatPair(typeof(ITypeListing), ReportFormat.Html4), "Sai.Core.Reporting.ListingHtml4.xslt");
            
            this.typeFileMap.Add(new TypeFormatPair(typeof(IProductReleaseDifference), ReportFormat.Md), "Sai.Core.Reporting.SummaryMd.xslt");
            this.typeFileMap.Add(new TypeFormatPair(typeof(IAssemblyDifference), ReportFormat.Md), "Sai.Core.Reporting.AssemblyMd.xslt");
            this.typeFileMap.Add(new TypeFormatPair(typeof(ITypeDifference), ReportFormat.Md), "Sai.Core.Reporting.TypeMd.xslt");
            this.typeFileMap.Add(new TypeFormatPair(typeof(ITypeListing), ReportFormat.Md), "Sai.Core.Reporting.ListingMd.xslt");

            this.typeFileMap.Add(new TypeFormatPair(typeof(IProductReleaseDifference), ReportFormat.Maml), "Sai.Core.Reporting.SummaryMaml.xslt");
            this.typeFileMap.Add(new TypeFormatPair(typeof(IAssemblyDifference), ReportFormat.Maml), "Sai.Core.Reporting.AssemblyMaml.xslt");
            this.typeFileMap.Add(new TypeFormatPair(typeof(ITypeDifference), ReportFormat.Maml), "Sai.Core.Reporting.TypeMaml.xslt");
            this.typeFileMap.Add(new TypeFormatPair(typeof(ITypeListing), ReportFormat.Maml), "Sai.Core.Reporting.ListingMaml.xslt");

            this.typeFileMap.Add(new TypeFormatPair(typeof(IProductReleaseDifference), ReportFormat.Xml), "XmlSummary.xslt");
            this.typeFileMap.Add(new TypeFormatPair(typeof(IAssemblyDifference), ReportFormat.Xml), "XmlAssembly.xslt");
            this.typeFileMap.Add(new TypeFormatPair(typeof(ITypeDifference), ReportFormat.Xml), "XmlType.xslt");
            this.typeFileMap.Add(new TypeFormatPair(typeof(ITypeListing), ReportFormat.Xml), "XmlListing.xslt");
        }

        public IReportTransformation Find(Type objectType, ReportFormat format)
        {
            TypeFormatPair candidateKey = new TypeFormatPair(objectType, format);

            if (this.typeFileMap.ContainsKey(candidateKey))
            {
                return new EmbeddedResourceTransformation(this.typeFileMap[candidateKey]);
            }

            return null;
        }
    }
}
